import Vue from 'vue'
import Router from 'vue-router'
import store from "../store/store.js"

// 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题
const originalPush = Router.prototype.push
Router.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}

// import yi from "@/"

//登录页
const login=()=>import("@/components/login.vue")

//移动端显示的页面
const shouji=()=>import("@/components/shouji.vue");

//首页
const index=()=>import("@/components/index.vue")
//联系我们
const lianxiwowen=()=>import("@/components/lianxiwowen.vue")
//数据研究
const shujuyanjiu=()=>import("@/components/shujuyanjiu.vue")
//平台版本
const home=()=>import("@/components/shujuzhongxin/home.vue")
	//工作台
	const gongzuotai=()=>import("@/components/components/gongzuotai/gongzuotai1.vue")
	//数据搜索
	const shujusousuo=()=>import("@/components/components/shujusousuo/shujusousuo.vue")
		//达人搜索
		const darensousuo=()=>import("@/components/components/shujusousuo/zisousuo/darensousuo.vue")
		//带货达人搜索
		const daihuosousuo=()=>import("@/components/components/shujusousuo/zisousuo/daihuosousuo.vue")
		//商品搜索
		const shangpinsousuo=()=>import("@/components/components/shujusousuo/zisousuo/shangpinsousuo.vue")
		//视频搜索
		const shipinsousuo=()=>import("@/components/components/shujusousuo/zisousuo/shipinsousuo.vue")
		//品牌搜索
		const pinpaisousuo=()=>import("@/components/components/shujusousuo/zisousuo/pinpaisousuo.vue")
//创意洞察
	//实时热门视频
	const shishishipin=()=>import("@/components/components/chaungyidongcha/shishishipin.vue")
	//实时热点
	const shishiredian=()=>import("@/components/components/chaungyidongcha/shishiredian.vue")
	//热门音乐
	const remenyinyue=()=>import("@/components/components/chaungyidongcha/remenyinyue.vue")
	//热门话题
	const remenhuati=()=>import("@/components/components/chaungyidongcha/remenhuati.vue")
	//热点词云
	const redianciyun=()=>import("@/components/components/chaungyidongcha/redianciyun.vue")
	//创意精选
	const chuangyijingxuan=()=>import("@/components/components/chaungyidongcha/chuangyijingxuan.vue")
//监测分析
	//我的抖音号
	const douyinhao=()=>import("@/components/components/jiancefenxi/douyinhao.vue")
	//视频监测
	const shipinjiance=()=>import("@/components/components/jiancefenxi/shipinjiance.vue")
	//直播监测
	const zhibojiance=()=>import("@/components/components/jiancefenxi/zhibojiance.vue")
	//直播监测
	const huatijiance=()=>import("@/components/components/jiancefenxi/huatijiance.vue")
//达人分析
	//达人对比
	const darenduibi=()=>import("@/components/components/darenfenxi/darenduibi.vue")
	//粉丝解析
	const fensijiexi=()=>import("@/components/components/darenfenxi/fensijiexi.vue")
	//粉丝重合分析
	const fensichonghe=()=>import("@/components/components/darenfenxi/fensichonghe.vue")
	//平台达人分布
	const pingtaidaren=()=>import("@/components/components/darenfenxi/pingtaidaren.vue")
//电商带货
	//热门商品
	const remenshangping=()=>import("@/components/components/dianshangdaihuo/remenshangping.vue")
		//好物榜
		const haowubang=()=>import("@/components/components/dianshangdaihuo/remen_ziluyou/haowubang.vue")
		//访客榜
		const fangkebang=()=>import("@/components/components/dianshangdaihuo/remen_ziluyou/fangkebang.vue")
		//销量榜
		const xiaoliangbang=()=>import("@/components/components/dianshangdaihuo/remen_ziluyou/xiaoliangbang.vue")
		//潜力榜
		const qianlibang=()=>import("@/components/components/dianshangdaihuo/remen_ziluyou/qianlibang.vue")
	//带货达人榜
	const daihuodarenbang=()=>import("@/components/components/dianshangdaihuo/daihuodarenbang.vue")
	//直播达人榜
	const zhibodarenbang=()=>import("@/components/components/dianshangdaihuo/zhibodarenbang.vue")
	//带货视频榜
	const daihuoshipinbang=()=>import("@/components/components/dianshangdaihuo/daihuoshipinbang.vue")
//直播分析
	//小时榜
	const xiaoshibang=()=>import("@/components/components/zhibofenxi/xiaoshibang.vue")
	//音浪收入榜
	const yinlangbang=()=>import("@/components/components/zhibofenxi/yinlangbang.vue")
//品牌追踪
	//我的品牌
	const wodepinpai=()=>import("@/components/components/pinpaizuizong/wodepinpai.vue")
//收藏夹
	const shoucangjia=()=>import("@/components/components/shoucangjia.vue")
//续费中心
	const xufeizhongxin=()=>import("@/components/components/xufeizhongxin/xufeizhongxin.vue")
	//购买会员
	const goumaihuiyuan=()=>import("@/components/components/xufeizhongxin/xufeizi/goumaihuiyuan.vue")
	//购买记录
	const chongzhicishu=()=>import("@/components/components/xufeizhongxin/xufeizi/chongzhicishu.vue")
//个人中心
	const gerenzhongxin=()=>import("@/components/components/gerenzhongxin/gerenzhongxin.vue")
	//个人信息
	const gerenxinxi=()=>import("@/components/components/gerenzhongxin/gerenzilu/gerenxinxi.vue")
	//购买记录
	const jilu=()=>import("@/components/components/gerenzhongxin/gerenzilu/jilu.vue")
//达人详情页
	const darenxiangqingye=()=>import("@/components/components/darenxiangqing/darenxiangqingye.vue")
	//数据概览
	const shujugailan=()=>import("@/components/components/darenxiangqing/sanbankuai/shujugailan.vue")
	//粉丝画像
	const fensihuaxiang=()=>import("@/components/components/darenxiangqing/sanbankuai/fensihuaxing.vue")
	//作品列表
	const zuopinliebiao=()=>import("@/components/components/darenxiangqing/sanbankuai/zuopinliebiao.vue")
//话题详情页
	const huatixiangqing=()=>import("@/components/components/huatixiangqing.vue")
//商品详情
	const shangpinxiangqing=()=>import("@/components/components/shangpinxiangqing/shangpinxiangqing.vue")
//404页面
	const Error=()=>import("@/components/silingsi.vue")

Vue.use(Router)

const routes=[
		{
			path:'',
			redirect:'/index',
			component:index
		},
		//当用户输入链接出错时，显示的404页面
		{
		   path:'*',
		   component:Error,
		   meta:{
			   title:'404页面'
		   }
		},
		//移动端显示页面
		{
			path:'/shouji',
			name:'shouji',
			component:shouji,
			meta:{
				title:"深码数据监控中心"
			}
		},
		//pc端显示页面
		{
			path: '/index',
			name: 'index',
			component: index,
			meta:{
				title:"深码数据-首页"
			}
		},
		{
			path:'/login',
			name:"login",
			component:login,
			meta:{
				title:"深码数据-登录"
			}
		},
		{
			path:'/shujuyanjiu',
			name:'shujuyanjiu',
			component:shujuyanjiu,
			meta:{
				title:"深码数据-数据研究"
			}
		},
		{
			path:"/lianxiwowen",
			name:"lianxiwm",
			component:lianxiwowen,
			meta:{
				title:"深码数据-联系我们"
			}
		},
		{
			path:'/home/:id',
			name:'home',
			component:home,
			meta:{
				title:"监控中心"
			},
			children:[
				{
					path:'',
					redirect:'gongzuotai',
					component:gongzuotai,
				},
				{
					path:'gongzuotai',
					name:'gongzuotai',
					component:gongzuotai,
					meta:{
						title:"监控中心-工作台",
						isAuth:true
					}
				},
				{
					path:"shujusousuo",
					name:'shujusousuo',
					component:shujusousuo,
					meta:{
						title:"监控中心-数据搜索"
					},
					children:[
						{
							path:'',
							redirect:'darensousuo',
							component:darensousuo,
						},
						{
							path:'darensousuo',
							name:'darensousuo',
							component:darensousuo,
							meta:{
								title:"监控中心-数据搜索-达人搜索"
							}
						},
						{
							path:'daihuosousuo',
							name:'daihuosousuo',
							component:daihuosousuo,
							meta:{
								title:"监控中心-数据搜索-带货达人搜索"
							}
						},
						{
							path:'shangpinsousuo',
							name:'shangpinsousuo',
							component:shangpinsousuo,
							meta:{
								title:"监控中心-数据搜索-商品搜索"
							}
						},
						{
							path:'shipinsousuo',
							name:'shipinsousuo',
							component:shipinsousuo,
							meta:{
								title:"监控中心-数据搜索-视频搜索"
							}
						},
						{
							path:'pinpaisousuo',
							name:'pinpaisousuo',
							component:pinpaisousuo,
							meta:{
								title:"监控中心-数据搜索-品牌搜索"
							}
						}
					]
				},
				{
					path:"shishishipin",
					name:shishishipin,
					component:shishishipin,
					meta:{
						title:"监控中心—实时热门视频"
					}
				},
				{
					path:"shishiredian",
					name:"shishiredian",
					component:shishiredian,
					meta:{
						title:"监控中心—实时热点"
					}
				},
				{
					path:"remenyinyue",
					name:'remenyinyue',
					component:remenyinyue,
					meta:{
						title:"监控中心—热门音乐"
					}
				},
				{
					path:"remenhuati",
					name:"remenhuati",
					component:remenhuati,
					meta:{
						title:"监控中心—热门话题"
					}
				},
				{
					path:"redianciyun",
					name:"redianciyun",
					component:redianciyun,
					meta:{
						title:"监控中心—热点词云"
					}
				},
				{
					path:"chuangyijingxuan",
					name:'chuangyijingxuan',
					component:chuangyijingxuan,
					meta:{
						title:"监控中心—创意精选"
					}
				},
				{
					path:"douyinhao",
					name:'douyinhao',
					component:douyinhao,
					meta:{
						title:"监控中心—我的抖音号"
					}
				},
				{
					path:"shipinjiance",
					name:"shipinjiance",
					component:shipinjiance,
					meta:{
						title:"监控中心—视频监测"
					}
				},
				{
					path:"zhibojiance",
					name:"zhibojiance",
					component:zhibojiance,
					meta:{
						title:"监控中心-直播监测"
					}
				},
				{
					path:"huatijiance",
					name:"huatijiance",
					component:huatijiance,
					meta:{
						title:"监控中心-话题监测"
					}
				},
				{
					path:"darenduibi",
					name:"darenduibi",
					component:darenduibi,
					meta:{
						title:"监控中心-达人对比"
					}
				},
				{
					path:"fensijiexi",
					name:"fensijiexi",
					component:fensijiexi,
					meta:{
						title:"监控中心-粉丝解析"
					}
				},
				{
					path:"fensichonghe",
					name:"fensichonghe",
					component:fensichonghe,
					meta:{
						title:"监控中心-粉丝重合分析"
					}
				},
				{
					path:"pingtaidaren",
					name:"pingtaidaren",
					component:pingtaidaren,
					meta:{
						title:"监控中心-平台达人分布"
					}
				},
				{
					path:"remenshangping",
					name:"remenshangping",
					component:remenshangping,
					meta:{
						title:'监控中心-热门商品'
					},
					children:[
						{
							path:'',
							redirect:'haowubang',
							component:haowubang
						},
						{
							path:'haowubang',
							name:"haowubang",
							component:haowubang,
							meta:{
								title:'监控中心-热门商品-好物榜'
							}
						},
						{
							path:'fangkebang',
							name:"fangkebang",
							component:fangkebang,
							meta:{
								title:'监控中心-热门商品-访客榜'
							}
						},
						{
							path:'xiaoliangbang',
							name:"xiaoliangbang",
							component:xiaoliangbang,
							meta:{
								title:'监控中心-热门商品-销量榜'
							}
						},
						{
							path:'qianlibang',
							name:"qianlibang",
							component:qianlibang,
							meta:{
								title:'监控中心-热门商品-潜力榜'
							}
						}
					]
				},
				{
					path:'daihuodarenbang',
					name:'daihuodarenbang',
					component:daihuodarenbang,
					meta:{
						title:'监控中心-带货达人榜'
					}
				},
				{
					path:'zhibodarenbang',
					name:'zhibodarenbang',
					component:zhibodarenbang,
					meta:{
						title:'监控中心-直播达人榜'
					}
				},
				{
					path:'daihuoshipinbang',
					name:'daihuoshipinbang',
					component:daihuoshipinbang,
					meta:{
						title:'监控中心-带货视频榜'
					}
				},
				{
					path:'xiaoshibang',
					name:'xiaoshibang',
					component:xiaoshibang,
					meta:{
						title:'监控中心-小时榜'
					}
				},
				{
					path:'yinlangbang',
					name:'yinlangbang',
					component:yinlangbang,
					meta:{
						title:'监控中心-音浪收入榜'
					}
				},
				{
					path:'wodepinpai',
					name:'wodepinpai',
					component:wodepinpai,
					meta:{
						title:'监控中心-我的品牌'
					}
				},
				{
					path:'shoucangjia',
					name:'shoucangjia',
					component:shoucangjia,
					meta:{
						title:'监控中心-收藏夹'
					}
				},
				{
					path:'xufeizhongxin',
					name:'xufeizhongxin',
					component:xufeizhongxin,
					meta:{
						title:'监控中心-续费中心'
					},
					children:[
						{
							path:'',
							redirect:'goumaihuiyuan',
							component:goumaihuiyuan
						},
						{
							path:'goumaihuiyuan',
							name:'goumaihuiyuan',
							component:goumaihuiyuan,
							meta:{
								title:'监控中心-续费中心-购买会员'
							}
						},
						{
							path:'chongzhicishu',
							name:'chongzhicishu',
							component:chongzhicishu,
							meta:{
								title:'监控中心-续费中心-充值次数'
							}
						}
					]
				},
				{
					path:'gerenzhongxin',
					name:'gerenzhongxin',
					component:gerenzhongxin,
					meta:{
						title:'监控中心-个人中心'
					},
					children:[
						{
							path:'',
							redirect:'gerenxinxi',
							component:gerenxinxi
						},
						{
							path:'gerenxinxi',
							name:'gerenxinxi',
							component:gerenxinxi,
							meta:{
								title:'监控中心-个人中心-个人信息'
							}
						},
						{
							path:'jilu',
							name:'jilu',
							component:jilu,
							meta:{
								title:'监控中心-个人中心-购买记录'
							}
						}
					]
				},
				{
					path:'darenxiangqingye',
					name:'darenxiangqingye',
					component:darenxiangqingye,
					meta:{
						title:'达人-详情页',
						isAuth:true
					},
					children:[
						{
							path:'',
							redirect:'shujugailan',
							component:shujugailan
						},
						{
							path:'shujugailan',
							name:'shujugailan',
							component:shujugailan,
							meta:{
								title:'达人-详情页-数据概览',
								isAuth:true
							}
						},
						{
							path:'fensihuaxiang',
							name:'fensihuaxiang',
							component:fensihuaxiang,
							meta:{
								title:'达人-详情页-粉丝画像'
							}
						},
						{
							path:'zuopinliebiao',
							name:'zuopinliebiao',
							component:zuopinliebiao,
							meta:{
								title:'达人-详情页-作品列表'
							}
						}
					]
				},
				{
					path:'huatixiangqing',
					name:'huatixiangqing',
					component:huatixiangqing,
					meta:{
						title:'话题详情页'
					}
				},
				{
					path:'shangpinxiangqing',
					name:'shangpinxiangqing',
					component:shangpinxiangqing,
					meta:{
						title:'商品详情页'
					}
				}
			]
		}
  ]
  const router = new Router({
	  routes,
	  // mode:'history'//取消页面路径前面的#符号
	  mode:'hash'
  })
  //导航守卫--可以实现登登录前后判断页面跳转
  router.beforeEach((to,form,next)=>{
    //存储路由中的id值在vuex中
    if(to.path.split("/")[2]!=undefined){
      store.state.luyoushu=to.path.split("/")[2];
    }
    //判断当前进入的是什么平台(抖音、快手、小红书、微博、bibi等等)
    var panlu=store.state.luyoushu;
    if(panlu==0){
      store.state.pintaiName="抖音";
    }else if(panlu==1){
      store.state.pintaiName="快手";
    }
    else if(panlu==2){
      store.state.pintaiName="B站";
    }
    else if(panlu==3){
      store.state.pintaiName="微博";
    }else if(panlu==4){
      store.state.pintaiName="小红书";
    }
    //获取vuex中的token,是都处于登录的状态
    // const token=store.state.token ? store.state.token:window.sessionStorage.getItem("token");
    const token=store.state.token ? store.state.token:window.localStorage.getItem("token");
    // console.log(token,"token")
    //判断该路由是否需要登录权限
    if(to.meta.isAuth){
      //通过vuex中的state获取当前的token是否存在
      if(token=="" || token==null){
        next({
          path:'/login',
        })
      }else{
        next();
      }
    }else{
      // 让页面回到顶部---效果(滚动动画回到顶部)
      let top = document.documentElement.scrollTop || document.body.scrollTop;
      // 实现滚动效果 
      const timeTop = setInterval(() => {
        document.body.scrollTop = document.documentElement.scrollTop = top -= 50;
        if (top <= 0) {
          clearInterval(timeTop);
        }
      }, 20);
      //从form跳转到to
      if(to.matched.length==1){
        document.title=to.matched[0].meta.title;
      }
      if(to.matched.length==2){
        document.title=to.matched[1].meta.title;
      }
      if(to.matched.length==3){
        document.title=to.matched[2].meta.title;
      }
      next()
    }
  })
  //当路由销毁时触发
  router.afterEach((to,from,next)=>{
	  //每次路由销毁时，让页面回到顶部
	  // window.scrollTop(0,0);
  })
  
export default router